package cn.hchaojie.javase.day08;

// Student: 外部类
public class Student {
	private String name = "学生";
	
	private int age;
	
	private Teacher teacher = new Teacher();
	private Parent parent = new Parent();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public void study() {
		System.out.println("正在学习。。。");
		
		teacher.onStudy();
		parent.onStudy();
	}
	
	private void play() {
		System.out.println("play...");
	}
	
	// Teacher：内部类
	class Teacher implements Listener {
		private String name = "老师";

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
		
		private void play() {
			System.out.println("teacher play...");
		}

		@Override
		public void onStudy() {
			System.out.println("好好学习，天天向上！");
			
			// 内部类访问外部类的私有字段和私有访问，就和访问自己的一样
			System.out.println(age);
			
			// 直接访问同名的字段和方法，是优先访问自己的。
			System.out.println("name:" + name);
			play();
			
			// 如何调用外部类的同名字段和方法？ 外部类名字.this (获取外部类的引用)
			System.out.println("name:" + Student.this.name);
			// Student.this
			// this
			Student.this.play();		
		}
	}
	
	// Type 类型
	
	interface Listener {
		void onStudy();
	}
	
	class Parent implements Listener {

		@Override
		public void onStudy() {
			System.out.println("好孩子，零花钱得多给一点。。。");
		}
	}
}
